package com.wom.gui;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.EnumMap;

import com.wom.player.ThePlayer;
import com.wom.worldmaker.GameWorld;

public class KeyHandler implements KeyListener{
	
	
public static boolean jumpKeyDown=false;
public static  boolean jumpLongPressed=false;

public static float jumpTime=0.0f;




private GameApplet app;

public static boolean canContinueJump=false;
	
	public KeyHandler(GameApplet gameApplet){
		
		app=gameApplet;
	
	}
	
	
	public void keyPressed(KeyEvent e) {
		if(e.getKeyCode()==KeyEvent.VK_B){
			app.addBlockType=BlockTypes.Dirt;
			System.out.println("Selected: dirt");
		}else if(e.getKeyCode()==KeyEvent.VK_N){
			app.addBlockType=BlockTypes.Sand;
			System.out.println("Selected: sand");
		}else if(e.getKeyCode()==KeyEvent.VK_M){
			app.addBlockType=BlockTypes.Rock;
			System.out.println("Selected: rock");
		}else if(e.getKeyCode()==KeyEvent.VK_L){
			app.addBlockType=BlockTypes.water;
			System.out.println("Selected: water");
		}
		
		
		if(e.getKeyCode()==KeyEvent.VK_A || e.getKeyCode()==KeyEvent.VK_LEFT){
			//System.out.println("left pressed");
			GameWorld.player.xDirection= -GameWorld.player.walkingSpeed;
			GameWorld.player.walking=true;
			
		}
		
		if(e.getKeyCode()==KeyEvent.VK_D || e.getKeyCode()==KeyEvent.VK_RIGHT){
		//System.out.println("right pressed");
			GameWorld.player.xDirection= GameWorld.player.walkingSpeed;
			GameWorld.player.walking=true;
			
		}
		
		if(e.getKeyCode()==KeyEvent.VK_SPACE){
	
		
			GameWorld.player.jumping=true;
		
	
			
									
						
		}
	
		
	}
	
	


	@Override
	public void keyReleased(KeyEvent e) {
		if(e.getKeyCode()==KeyEvent.VK_A || e.getKeyCode()==KeyEvent.VK_LEFT){
			//System.out.println("LEft released");
			if(GameWorld.player.xDirection== -GameWorld.player.walkingSpeed){
				GameWorld.player.walking=false;
			}
		}
		
		if(e.getKeyCode()==KeyEvent.VK_D || e.getKeyCode()==KeyEvent.VK_RIGHT){
			//System.out.println("LEft released");
			if(GameWorld.player.xDirection== GameWorld.player.walkingSpeed){
				GameWorld.player.walking=false;
			}
		}
		
		if(e.getKeyCode()==KeyEvent.VK_SPACE){
			
		
		
			GameWorld.player.jumping=false;
			
		
		
			
			
		}
		
	}


	@Override
	public void keyTyped(KeyEvent e) {
		
		
	}


}
